package com.commerceerp.system.service.Impl;

import com.commerceerp.system.entity.FxUserInfo;
import com.commerceerp.system.mapper.FxRoleInfoMapper;
import com.commerceerp.system.mapper.FxUserInfoMapper;
import com.commerceerp.system.service.FxUserService;
import com.commerceerp.system.util.DateUtil;
import com.commerceerp.system.util.MD5Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class FxUserServiceImpl implements FxUserService {

    @Autowired
    private FxUserInfoMapper fxUserInfoMapper;

    @Autowired
    private FxRoleInfoMapper fxRoleInfoMapper;

    /**
     * 分销商户申请列表
     * @param loginUserId
     * @return
     */
    @Override
    public List<FxUserInfo> getFxApplyAccountByLoginUser(String loginUserId) {

        List<FxUserInfo> list = this.fxUserInfoMapper.getFxApplyAccountByLoginUser(loginUserId);

        return list;
    }


    /**
     * 新增分销用户信息
     * @param fxUserInfo
     * @return
     */
    @Override
    public Integer addFxUserInfo(FxUserInfo fxUserInfo) {

        fxUserInfo.setUserCreateTime(DateUtil.getYMDHMSDate());
        fxUserInfo.setUserIsCancel("1");
        fxUserInfo.setUserAccountState("1");

        Integer success = this.fxUserInfoMapper.addFxUserInfo(fxUserInfo);

        return success;
    }


    /**
     * 分销商户申请审核列表
     * @param userAccountState
     * @param beginTime
     * @param endTime
     * @return
     */
    @Override
    public List<FxUserInfo> getFxApplyUserInfoToAudting(String userAccountState, String beginTime, String endTime) {

        List<FxUserInfo> list = this.fxUserInfoMapper.getFxApplyUserInfoToAudting(userAccountState,beginTime,endTime);

        return list;
    }


    /**
     * 编辑分销用户信息
     * @param fxUserInfo
     * @return
     */
    @Override
    public Integer updateFxUserInfo(FxUserInfo fxUserInfo) {

        Integer success = this.fxUserInfoMapper.updateFxUserInfo(fxUserInfo);

        return success;
    }

    @Override
    public FxUserInfo getFxUserInfoByUserId(String userId) {

        FxUserInfo fxUserInfo = this.fxUserInfoMapper.getFxUserInfoByUserId(userId);

        return fxUserInfo;
    }


    /**
     * 判断erp用户是否是分销商户，有分销商品的权限
     * @param erpUserId
     * @return
     */
    @Override
    public Integer getFxGoodPowerByErpUser(String erpUserId) {

        return fxUserInfoMapper.getFxGoodPowerByErpUser(erpUserId);
    }

    @Override
    public List<Map> getAllUserInfoList(String username, String phone) {
        return this.fxRoleInfoMapper.getAllUserInfoList(username,phone);
    }

    @Override
    public int updUserRoleOrPassword(String id, String roleId,Integer delFlag,String password) {
        String pawDES = null;
        if(password != null && "".equals(password)){
            pawDES = MD5Tools.getSHA256StrJava(password);
        }
        return this.fxRoleInfoMapper.updUserRoleOrPassword(id,roleId,delFlag,pawDES);
    }
}
